package com.jm.product.entity;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "es_goods_spec")
@Cache(region = "com.jm.cache", usage = CacheConcurrencyStrategy.READ_WRITE)
public class GoodsSpec extends IdEntity<Integer> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@ManyToOne
    @JoinColumn(name = "spec_id")
	private Specification specification;
	@ManyToOne
    @JoinColumn(name = "spec_value_id")
	private SpecValues specValues;
	@ManyToOne
    @JoinColumn(name = "goods_id")
	private Goods goods;
	@ManyToOne
    @JoinColumn(name = "product_id")
	private Product product;
	
	public Specification getSpecification() {
		return specification;
	}
	public void setSpecification(Specification specification) {
		this.specification = specification;
	}
	public SpecValues getSpecValues() {
		return specValues;
	}
	public void setSpecValues(SpecValues specValues) {
		this.specValues = specValues;
	}
	public Goods getGoods() {
		return goods;
	}
	public void setGoods(Goods goods) {
		this.goods = goods;
	}
	public Product getProduct() {
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((goods == null) ? 0 : goods.hashCode());
		result = prime * result + ((product == null) ? 0 : product.hashCode());
		result = prime * result + ((specValues == null) ? 0 : specValues.hashCode());
		result = prime * result + ((specification == null) ? 0 : specification.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GoodsSpec other = (GoodsSpec) obj;
		if (goods == null) {
			if (other.goods != null)
				return false;
		} else if (!goods.equals(other.goods))
			return false;
		if (product == null) {
			if (other.product != null)
				return false;
		} else if (!product.equals(other.product))
			return false;
		if (specValues == null) {
			if (other.specValues != null)
				return false;
		} else if (!specValues.equals(other.specValues))
			return false;
		if (specification == null) {
			if (other.specification != null)
				return false;
		} else if (!specification.equals(other.specification))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "GoodsSpec [specification=" + specification + ", specValues=" + specValues + ", goods=" + goods
				+ ", product=" + product + "]";
	}
	
}
